package Test;


import com.config.MyBatisConfig;
import com.config.SpringConfig;
import com.domain.Book;
import com.service.BookService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={SpringConfig.class, MyBatisConfig.class})
public class BookServiceTest {
    @Autowired
    private BookService bookService;

    @Test
    public void findByIdTest(){
        System.out.println(bookService.findById("1"));
    }

    @Test
    public void findAllTest(){
        System.out.println(bookService.findTypeAll(1,10));
    }

    @Test
    public void selectNewBooksTest(){
        System.out.println(bookService.selectNewBooks(1,10));
    }



    @Test
    public void addBookTest(){
        Book book=new Book();
        book.setName("数据结构");
        book.setBook_type("1");
        book.setAuthor("张大爷");
        book.setIsbn("1111111111111");
        book.setPagination(10);
        book.setPrice(100.0);
        book.setPress("上海出版社");
        System.out.println(bookService.addBook(book));
    }

    @Test
    public void selectBorrowedTest(){
        Book book=new Book();
        book.setId(1);
        book.setStatus("1");
        book.setBorrower("张三");
        book.setBorrowTime("2022-05-19");
        book.setReturnTime("2022-05-19");
        System.out.println(bookService.borrowBook(book));
    }
}
